<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.js"></script>
</head>
<body>
    用户名：<input type="text" id="username">
    密码：<input type="password" id="password">
    <button id="btn">提交</button>
    
    <script>
        document.getElementById("btn").onclick = function(){
            // fetch("请求地址",{请求方式、请求头、请求体,...})
            let request = fetch("http://localhost:3000/findUser",{
                method:"post",
                headers:{
                    "Content-Type":"application/json"
                },
                body:JSON.stringify({
                    username:document.getElementById("username").value,
                    password:document.getElementById("password").value,
                })
            })

            request.then(res => {
                console.log(res.json());
            })
            .then(res => {
                console.log(res);
            })

            


            // $.ajax({
            //     url:"http://localhost:3000/findUser",
            //     type:"post",
            //     data:{
            //         username:document.getElementById("username").value,
            //         password:document.getElementById("password").value,
            //         time:Date.now(),
            //         sex:"男"
            //     },
            //     success:function(data){
            //         console.log("成功请求的回调：",data);
            //     },
            //     error:function(err){
            //         console.log(err);
            //     }
            // })
        }
    </script>
</body>
</html>